/* OPERATIONS.H
 *
 * This file contains the declaration of the Task class and the
 * performOperation() method. The performOperation() method is called from
 * the MainWindow class, after the setup of the operation is completed.
 * Task instances are used as an argument for the setup methods. It
 * contains the original and destination images, the type of operation
 * and possibly some extra (operation specific) data. Some of these
 * members should be set in the setup method.
 */

#pragma once

#include <windows.h>
#include "dib.h"

class DIB;

/** 
 * \ingroup ti6
 *
 * \brief
 * A task to perform an operation on an image. The type of operation is
 * stored in the Task instance, not the exact operation number.
 *
 * Copyright (c) Academie voor ICT en Media 2007 - 2008
 */
class Task
{
public:
	/**
	 \brief
	 This is a function used in the setup functions for sizing operations.
	 It creates a destination image in the same format at the source image,
	 with the specified size.

	 \param width The width of the destination image, in pixels.
	 \param height The height of the destination image, in pixels.
	 \return True is returned if the destionation is successfully created.
	   In case of an error, false is returned.
	 */
	bool createDestination( unsigned int width, unsigned int height );
	bool createPaddedImage( unsigned int width, unsigned int height );

	/**
	 The original image. For dot operations, this image should contain the
	 result as well. File operations are an exception in the sense that
	 _originalImage is not the image which was already open, but the newly
	 opened image.
	 */
	DIB *_originalImage;
	DIB *_paddedImage;

	/**
	 The destination image. For sizing operations, begin by initializing this
	 image. This is done by the createDestination() method. The
	 _destinationImage member is not used for dot operations.
	 */
	DIB *_destinationImage;

	/**
	 A pointer for user data, which can be set in the setup function (main
	 thread) to use when processing the task. The function which processes
	 the task (the filter itself) is responsible for deleting this data.
	 */
	void *_data;

	enum {
		DOT_OPERATION,
		REBUILDING_OPERATION,
		SIZING_OPERATION,
		FILE_OPERATION
		} _operationType;
};

/**
 \brief
 Apply the specified operation to the image(s) in the specified task.
 
 \param *task The task which contains the correct operation type and
   the neccesary images.
 \param id The identifier for the operation.
 \return True is returned if the operation was successfull. In case
   of an error, false is returned.
 */
bool performOperation( Task *task, WORD id );
